package com.open.capacity.forum.feign;

import com.open.capacity.common.constant.ServiceNameConstant;
import com.open.capacity.common.exception.controller.ControllerException;
import com.open.capacity.common.web.Result;
import com.open.capacity.forum.feign.impl.PointsCenterServiceFallback;
import com.open.capacity.forum.feign.impl.UserCentServiceFallback;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @author 蒋鑫
 * @version 2021/3/8
 */
@FeignClient(value = ServiceNameConstant.POINTS, fallbackFactory = PointsCenterServiceFallback.class, decode404 = true)
public interface PointsCenterService {
    /**
     * 根据id查询用户积分
     *
     * @param userId
     * @return
     * @throws ControllerException
     */
    @GetMapping("/points/userId/{userId}")
    Result<Integer> findPointsByUserId(@PathVariable(value = "userId") long userId) throws ControllerException;

    /**
     * 积分规则（消费和获取积分）
     * @param userId 产生积分变动的用户Id
     * @param pointsRuleCode 积分规则  PointsRuleConstant
     * @param points 用户设定的积分值 默认为0
     * @return
     * @throws ControllerException
     */
    @PostMapping("/points/change")
    Result change(@RequestParam("userId") Long userId, @RequestParam("pointsRuleCode") String pointsRuleCode,
                  @RequestParam("points") int points) throws ControllerException;
}
